import Vue from "vue";
import App from "./App.vue";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
// import "../src/assets/less/index.less";
import "@/assets/index.scss";
import setBasicSize from '@/utils/rem'

import http from "@/api/axios";
import router from "@/router";
import store from "@/store";

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.prototype.$http = http;

if (window.Config.supportrem) {
    setBasicSize();
}

// vue 导航守卫
router.beforeEach((to, from, next) => {
    // store.commit('clearTenant')
    store.commit('getToken')
    const token = store.state.user.token;
    if (!token && to.name !== 'login') {
        next({
            name: 'login'
        })
        // } else if (token && to.name === 'login') {   // 如果是登录状态进去login页面，自动回到home页面
    } else if (token && to.name === null) {   // 如果是登录状态进去login页面，自动回到home页面
        next({ name: 'main' })
    } else {
        next()
    }
});
router.afterEach((to) => {
    document.title = to.meta.title;
})

new Vue({
    store,
    router,
    render: (h) => h(App),
    // created () {
    //     store.commit('addMenu', router);
    // }
}).$mount("#app");
